Skip to content

Fix mypy type errors unmasked in the test suite - #105

Merged
randileeharper merged 1 commit into
mainfrom
fix/mypy-test-errors-97
Jun 28, 2026
Merged

Fix mypy type errors unmasked in the test suite#105
randileeharper merged 1 commit into
mainfrom
fix/mypy-test-errors-97

Conversation

@randileeharper

Copy link
Copy Markdown
Owner

Summary

Closes #97.

Now that the duplicate-module error from #82 is fixed (#96 added tests/__init__.py), mypy vesper tests no longer aborts early — which unmasked 61 pre-existing type errors in the test suite (51 at issue-file time, plus new ones added since). This PR makes mypy vesper tests exit 0 while keeping production code clean.

Approach

The dominant pattern was test doubles not satisfying real type signatures. Mirroring the existing Resolver Protocol, this introduces structural Protocols so test doubles satisfy the real types rather than being papered over with ignores:

  • RpcClient / RpcSession Protocols (vesper/rpc.py): type the CiderRpcClient session param and all production rpc parameters against them (service, catalog, playback_controller, search_controller, session).
  • Resolver stubs inherit FallbackResolver (implements all 5 Protocol methods) so they satisfy the Resolver Protocol structurally.
  • RPC stubs gain the missing Protocol methods (set_failure_callback, playback_get, search_library, run_amapi_v3) and default parameter values.
  • Mechanical narrowing fixes for dict | None indexing, .text on content unions, utcoffset() None, and a generator fixture return annotation.
  • cast() at 7 sites that access stub-only attributes on typed service internals (is_playing, current_track, plan_calls).
  • types-jsonschema added to dev deps for the jsonschema import-untyped error.
  • _build_session_query_pool now accepts str | SessionSearchSource, matching the existing runtime isinstance(source, str) handling.

Test commands run

.venv/bin/python -m mypy vesper tests   # Success: no issues found in 52 source files
.venv/bin/python -m mypy vesper         # Success: no issues found in 37 source files
.venv/bin/python -m pytest -q           # 270 passed

Now that the duplicate-module error from #82 is fixed, mypy reaches the
test suite and reports 61 pre-existing type errors (51 originally, plus
new ones added since the issue was filed). This makes `mypy vesper tests`
exit 0 while keeping production code clean.

Production changes (structural typing, mirroring the existing Resolver
Protocol):
- Add RpcClient and RpcSession Protocols in vesper/rpc.py and type the
  CiderRpcClient session param and all production rpc parameters against
  them (service, catalog, playback_controller, search_controller, session).
- Accept str | SessionSearchSource in _build_session_query_pool, matching
  the existing runtime isinstance(source, str) handling.

Test changes:
- Resolver stubs now inherit from FallbackResolver (implements all 5
  Protocol methods) so they satisfy the Resolver Protocol structurally.
- RPC stubs gain the missing Protocol methods and default parameter
  values so they satisfy RpcClient.
- Mechanical narrowing fixes for dict|None indexing, .text on content
  unions, utcoffset() None, and a generator fixture return annotation.
- cast() at 7 sites that access stub-only attributes on typed service
  internals (is_playing, current_track, plan_calls).
- Add types-jsonschema to dev deps for the jsonschema import-untyped error.

Verified: mypy vesper tests exits 0; 270 tests pass.
@randileeharper
randileeharper merged commit 46c0876 into main Jun 28, 2026
1 check passed
@randileeharper
randileeharper deleted the fix/mypy-test-errors-97 branch June 28, 2026 19:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

mypy: fix 51 pre-existing type errors unmasked in the test suite

1 participant